<template>
  <div id="home"></div>
</template>

 <script>
import { mapActions, mapGetters } from "vuex";
import * as echarts from "echarts";
export default {
  data() {
    return {};
  },
  watch: {
    catelist: {
      handler() {
        var myChart = echarts.init(document.getElementById("home"));

        // var option = {
        //   xAxis: {
        //     type: "category",
        //     data: this.catelist.map((item) => item.catename),
        //   },
        //   yAxis: {
        //     type: "value",
        //   },
        //   series: [
        //     {
        //       data: this.catelist.map((item) => item.children.length),
        //       type: "bar",
        //     },
        //   ],
        // };

       var option = {
          xAxis: {
            type: "category",
            data: this.catelist.map((item) => item.catename),
          },
          yAxis: {
            type: "value",
          },
          series: [
            {
              data: this.catelist.map((item) => item.children.length),
              type: "line",
            },
          ],
        };
        myChart.setOption(option);
      },
      deep: true,
    },
  },
  computed: {
    ...mapGetters({
      catelist: "cate/list",
    }),
  },
  methods: {
    ...mapActions({
      reqChangeCate: "cate/reqChangeCate",
    }),
  },
  mounted() {
    this.reqChangeCate();
    console.log(this.caetlist);
  },
};
</script>

<style scoped>
#home {
  width: 1000px;
  height: 500px;
}
</style>